package com.PictureSite.controller;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileUpload;

import com.PictureSite.DatabaseAccess.PictureSiteCreatePostDAO;
import com.PictureSite.model.PictureSitePostModel;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.appengine.api.files.FileService;

public class PictureSiteImageController extends PictureSiteController {

	private final FileService fileService;

	public PictureSiteImageController(final FileService fileService) {
		this.fileService = fileService;
	}

	public void imageSelector(HttpServletRequest req, HttpServletResponse resp,
			PictureSitePostModel model) {
		
		//Need to remake and have servlet based parameter extraction.
		String blobKeyStr = req.getPathInfo().replace("/", "");
		BlobKey blobKey = new BlobKey(blobKeyStr);
		BlobstoreService blobStoreService = BlobstoreServiceFactory.getBlobstoreService();
		
		try {
			blobStoreService.serve(blobKey, resp);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
